package net.learn2develop.TestMap;

import android.app.Activity;   


import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

import android.view.KeyEvent;
import com.google.android.maps.MapController;
import com.google.android.maps.GeoPoint;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import com.google.android.maps.Overlay;
import java.util.List;



public class MapTestActivity extends MapActivity {
	MapView mapView;
	MapController mc;
	GeoPoint p;
	
	private LocationManager lm;
	private LocationListener locationListener;
	
	class MapOverlay extends com.google.android.maps.Overlay
	{
		public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
		{
			super.draw(canvas,  mapView, shadow);
			
			Point screenPts = new Point();
			mapView.getProjection().toPixels(p, screenPts);
			
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
			canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
			return true;
		}
	}
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
        
        mc = mapView.getController();
        
        String coordinates[] = {"38.346548", "-75.6065631"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);
        p = new GeoPoint(
        		(int) (lat * 1E6), (int) (lng * 1E6));
        mc.animateTo(p);
        mc.setZoom(17);
        
        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = mapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);
        
        mapView.invalidate();
        
     //   lm = (LocationManager)
        //		getSystemService(Context.LOCATION_SERVICE);
        
      // locationListener = new MyLocationListener();
       
       //lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
       
               
    }
    
   // private class MyLocationListener implements LocationListener
    //{
    	//public void onLocationChanged(Location loc){
    		//p = new GeoPoint(
    			//	(int) (loc.getLatitude() * 1E6),
    				//(int) (loc.getLongitude() * 1E6));
    		
    	//	mc.animateTo(p);
    	//	mc.setZoom(18);
    //	}
    	
    	//public void onProviderDisabled(String provider){}
    	
    //	public void onProviderEnabled(String provider){}
    	
    //	public void onStatusChanged(String provider, int status, Bundle extras){}
    	
   // }
    	
    
    
    
    protected boolean isRouteDisplayed(){
    	// TODO Auto-generated method stub
    	return false;
    }
}